package com.zzh.core;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.EditText;
import android.widget.TextView;

import com.zzh.lib.core.HLibrary;
import com.zzh.lib.core.utils.HDeviceUtils;
import com.zzh.lib.core.utils.HNetUtils;
import com.zzh.lib.core.utils.HResUtils;
import com.zzh.lib.core.utils.LogUtils;

/**
 * Created by ZZH on 2022/2/28.
 *
 * @Date: 2022/2/28
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 设备信息
 */
public class DeviceInfoActivity extends Activity {
    TextView tv_device_info, scan_info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_device_info);
        tv_device_info = findViewById(R.id.tv_device_info);
        scan_info = findViewById(R.id.scan_info);
        StringBuilder builder = new StringBuilder();
        builder.append("设备名称：\t\t").append(HDeviceUtils.getDeviceDevice());
        builder.append("手机型号：\t\t").append(HDeviceUtils.getDeviceModel()).append("\n");
        builder.append("手机(运存)RAM：\t\t").append(HDeviceUtils.getTotalRAM()).append("\n");
        builder.append("手机可用运存：\t\t").append(HDeviceUtils.getAvailableRAM()).append("\n");


        builder.append("屏幕尺寸宽：\t\t").append(HResUtils.getDisplayWidth()).append("\n");
        builder.append("屏幕尺寸高：\t\t").append(HResUtils.getDisplayHeight()).append("\n");

        builder.append("ActionBarSize：\t\t").append(HResUtils.getActionBarHeight()).append("\n");
        builder.append("StatusBarSize：\t\t").append(HResUtils.getStatusBarHeight()).append("\n");
        builder.append("Nav Bar Size：\t\t").append(HResUtils.getNavBarHeight()).append("\n");

        builder.append("tags：\t\t").append(Build.TAGS).append("\n");
        builder.append("user：\t\t").append(Build.USER).append("\n");
        builder.append("SERIAL：\t\t").append(Build.SERIAL).append("\n");
        builder.append("BRAND：\t\t").append(Build.BRAND).append("\n");
        builder.append("BOARD：\t\t").append(Build.BOARD).append("\n");
        builder.append("CPU：\t\t").append(HDeviceUtils.getCPUAbi()).append("\n");
        builder.append("IP：\t\t").append(HNetUtils.getIpv4Address()).append("\n");

        boolean hasMenuKey = ViewConfiguration.get(HLibrary.getAppContext()).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

        builder.append("hasMenuKey \t\t").append(hasMenuKey).append("\n");
        builder.append("hasBackKey \t\t").append(hasBackKey).append(
                "\n"
        );
        builder.append("nav bar height \t\t").append(HResUtils.getNavBarHeight()).append("\n");

        tv_device_info.setText(builder.toString());
        LogUtils.d("这是一个测试用例日志");
        EditText scan = findViewById(R.id.scan);
        scan.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                LogUtils.e(keyCode + ", " + event.toString());
                scan_info.setText(keyCode + ", " + event.toString());
                return false;
            }
        });
    }
}
